using System;
using System.Text;

namespace Aks.Deployment.SharePoint.Data
{
	/// <summary>
	/// Represents a CAML field node.
	/// </summary>
	internal class CamlField : CamlNode
	{
		/// <summary>Field reference XML format. Arguments include: (0) field name.</summary>
		protected const string CamlFormat = @"<FieldRef Name='{0}'/>";


		/// <summary>
		/// Initializes a new instance of the <see cref="CamlField"/> class.
		/// </summary>
		/// <param name="name">The name.</param>
		public CamlField(string name)
		{
			Name = name;
		}


		/// <summary>
		/// Gets or sets the name.
		/// </summary>
		/// <value>The name.</value>
		public string Name { get; set; }


		/// <summary>
		/// Returns a string that represents the current CAML node.
		/// </summary>
		/// <returns>
		/// A string representation of the CAML node.
		/// </returns>
		public override string ToCaml()
		{
			return String.Format(CamlFormat, Name);
		}


		/// <summary>
		/// Returns a string that represents the specified CAML <paramref name="fields"/>.
		/// </summary>
		/// <param name="fields">The fields.</param>
		/// <returns>A string representation of the CAML fields.</returns>
		public static string GetFieldList(params string[] fields)
		{
			var caml = new StringBuilder();
			for (var i = 0; i < fields.Length; i++)
			{
				caml.AppendFormat(CamlFormat, fields[i]);
			}
			return caml.ToString();
		}
	}
}